import { TEST_ADD, TEST_SUBTRACT, GET_COUNT, INITIALIZE } from '../mutation-types'

const state = {
  count: 0
}

// getters
const getters = {
  [GET_COUNT]: state => state.count
}

// mutations
const mutations = {
  [TEST_ADD] (state) {
    state.count++
  },
  [TEST_SUBTRACT] (state) {
    state.count--
  },
  [INITIALIZE] (state, param) {
    state.count += param
  }
}

// actions
const actions = {
  [TEST_ADD] ({commit, state}) {
    commit(TEST_ADD)
  },
  [TEST_SUBTRACT] ({commit, state}) {
    commit(TEST_SUBTRACT)
  },
  [INITIALIZE] ({commit, state}, param) {
    commit(INITIALIZE, param)
  }
}

export default {
  state,
  getters,
  mutations,
  actions
}
